{extend name="public:base" /}


{block name="css"}
<link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css"/>
<link rel="stylesheet" type="text/css" href="__ADMIN__/css/style.css">
{/block}

{block name="content"}

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox ">
                <div class="ibox-content">
                    <form method="post">
                        <div class="box-item">
                            <div class="form-group row layui-form">
                                <label class="col-sm-1 col-form-label">类别</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" value="{$info.type_name}" readonly>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="box-item">
                            <div class="form-group row layui-form">
                                <label class="col-sm-1 col-form-label">明细科目</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" value="{$info.title}" readonly>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="box-item">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">发票种类</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" value="{$info.desc}" readonly>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="box-item">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">发票明细</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" oninput="changePrice(this)" value="{$info.price_text}">
                                    <input type="hidden" class="price_text" name="price_text" value="{$info.price_text}">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="box-item">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">发票数量</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control count" name="count" value="{$info.count}" readonly>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="box-item">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">发票金额</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control all_price" name="all_price" value="{$info.all_price}" readonly>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <input type="hidden" name="id" value="{$info['id']}">
                        <input type="hidden" name="company_id" value="{$info['company_id']}">

                        <div class="form-group row">
                            <div class="col-sm-4 col-sm-offset-2">
                                <button type="button" class="btn btn-w-m btn-default back-page">返回</button>
                                <button type="button" class="btn btn-w-m btn-primary ajax-post">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

{/block}
{block name='js'}
<script src="__STATIC__/layui/layui.js"></script>
<script>
    function parseNumbersInfo(inputStr) {
        // 将中文逗号替换成英文逗号
        let cleanedStr = inputStr.replace(/，/g, ',');
        // 按英文逗号分割
        let parts = cleanedStr.split(',');
        // 转换成数字并过滤掉非法项
        let numbers = parts.map(item => parseFloat(item)).filter(num => !isNaN(num));

        let sum = numbers.reduce((total, num) => total + num, 0);
        let count = numbers.length;

        return {
            sum,
            count,
            numbers
        };
    }

    function changePrice(that) {
        var value = $(that).val();

        var result = this.parseNumbersInfo(value)

        $('.price_text').val(result.numbers);
        $('.count').val(result.count);
        $('.all_price').val(result.sum)
    }
</script>
{/block}
